package com.dragon.logical.service.customer.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.entity.OperationRecord;
//import com.dragon.repository.entity.Project;
import com.dragon.repository.mapper.OperationRecordMapper;
import com.dragon.logical.service.customer.IOperationRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.dragon.repository.mapper.ProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * “项目操作记录” 服务实现类
 * </p>
 *
 * @author sy
 * @since 2023-06-30
 */
@Service
public class OperationRecordServiceImpl extends ServiceImpl<OperationRecordMapper, OperationRecord> implements IOperationRecordService {


    @Autowired
    OperationRecordMapper mapper;

//    @Autowired
//    ProjectMapper projectMapper;
//
//
//    @Override
//    public Page<OperationRecord> selectPageList(Integer projectId,Integer customerId,Integer page,Integer limit){
//        Page<OperationRecord> recordPage = new Page<>(page,limit);
//        List<Integer> projectIds = new ArrayList<>();
//        //查询客户Id对应的项目Id
//        if(projectId == null){
//            QueryWrapper<Project> queryWrapper = new QueryWrapper<>();
//            queryWrapper.lambda().eq(Project::getCustomerId,customerId).select(Project::getId);
//            List<Project> projects = projectMapper.selectList(queryWrapper);
//            projectIds = projects.stream().map(Project::getId).collect(Collectors.toList());
//        }
//        if(projectIds!=null) projectIds.add(projectId);
//        return mapper.selectPageList(recordPage,projectIds);
//    }

    /**
     *
     * @param projectId 项目id
     * @param adminId  操作人id
     * @param cause    审核备注
     * @param actionType 操作类型
     * @param operationType 流程类型
     */
    @Override
    public void addOperationRecord(Integer projectId, Integer adminId, String cause, Integer actionType, Integer operationType){
        OperationRecord operationRecord = new OperationRecord();
        operationRecord.setProjectId(projectId);
        operationRecord.setAdminId(adminId);
        operationRecord.setRemark(cause);
        operationRecord.setActionType(actionType);
        operationRecord.setOperationType(operationType);
        operationRecord.setOperationTime(DateUtil.date());
        mapper.insert(operationRecord);
    }

}
